﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ColorPresentation
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            IniWrapPanel();
            this.Title = "ColorPresentation design by Charles Petzold";
        }

        /// <summary>
        /// 创建各种颜色的Lable,用以展示。
        /// </summary>
        /// <param name="lblColor">要创建的Label的颜色</param>
        /// <returns></returns>
        public static Label Createlbl(Color lblColor)
        {
            Label lbl = new Label();
            lbl.Height = 30;
            lbl.Width = 100;
            SolidColorBrush scb = new SolidColorBrush(lblColor);
            lbl.Background = scb;
            return lbl;
        }
        /// <summary>
        /// 初始化WrapPanel，其内容是各色标签。
        /// </summary>
        public void IniWrapPanel()
        {
            Type t = typeof(Colors);
            PropertyInfo[] pInfo = t.GetProperties();
            foreach (PropertyInfo pi in pInfo)
            {
                Color c = (Color)ColorConverter.ConvertFromString(pi.Name);
                Label lbl = Createlbl(c);
                lbl.Content = pi.Name;
                wp.Children.Add(lbl);
            }
        }
    }
}
